package com.ksd.modules.message.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.message.po.AdminMsgSystemSavePO;
import com.ksd.modules.message.po.AdminMsgSystemSearchPO;
import com.ksd.modules.message.service.IAdminMsgSystemService;
import com.ksd.modules.message.vo.AdminMsgSystemVo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminMsgSystemController extends BaseController {
    
    @Autowired
    private IAdminMsgSystemService adminMsgSystemService;

    /**
     * 【系统消息】- 列表
     * @return
     */
    @PostMapping("/sysmsg/list")
    public R<Page<AdminMsgSystemVo>> findAdminMsgSystems(@Validated @RequestBody AdminMsgSystemSearchPO adminMsgSystemSearchPO){
        return R.data(adminMsgSystemService.findAdminMsgSystems(adminMsgSystemSearchPO));
    }


    /**
     * 【系统消息】 - 保存和更新
     * @param adminMsgSystemSavePO
     * @return
     */
    @PostMapping("/sysmsg/saveupdate")
    @ApiLog("【系统消息】 - 保存和更新")
    @RepeatSubmit
    public R<AdminMsgSystemVo> saveUpdateAdminMsgSystem(@Validated @RequestBody AdminMsgSystemSavePO adminMsgSystemSavePO){
        return R.data(adminMsgSystemService.saveUpdateAdminMsgSystem(adminMsgSystemSavePO));
    }

    /**
     * 【系统消息】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/sysmsg/get/{id}")
    public R<AdminMsgSystemVo> getAdminMsgSystemById(@PathVariable("id")Long id){
        return R.data(adminMsgSystemService.getAdminMsgSystemById(id));
    }

    /**
     * 【系统消息】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/sysmsg/batch/remove")
    @ApiLog("【系统消息】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminMsgSystem(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminMsgSystemService.batchRemovesAdminMsgSystem(batchIdsPO));
    }

    /**
     * 【系统消息】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/sysmsg/remove/{id}")
    @ApiLog("【系统消息】- 根据ID恢复删除")
    public R<Boolean> removeAdminMsgSystemById(@PathVariable("id")Long id){
        return R.data(adminMsgSystemService.removeAdminMsgSystemById(id));
    }

    /**
     * 【系统消息】- 修改状态
     *
     * @return
     */
    @PostMapping("/sysmsg/status/{id}/{field}")
    @ApiLog("【系统消息】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminMsgSystemService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminMsgSystemService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【系统消息】-批量上架
     *
     * @return
     */
    @PostMapping("/sysmsg/batch/up")
    @ApiLog("批量上架")
    @RepeatSubmit
    @ApiOperation("【系统消息】-批量上架")
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminMsgSystemService.batchUps(batchIdsPO));
    }

    /**
     * 【系统消息】-批量下架
     *
     * @return
     */
    @PostMapping("/sysmsg/batch/down")
    @ApiLog("【系统消息】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminMsgSystemService.batchDowns(batchIdsPO));
    }

    /**
     * 【系统消息】-【章】-  复制数据
     * @param opid
     * @return
     */
    @PostMapping("/sysmsg/copy/{opid}")
    @ApiLog("【系统消息】-复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminMsgSystemService.copyData(opid));
    }
}
